/**
 * Predefined variables
 * Name = aEventBase
 * DateTime = Fri Feb 11 2022 11:09:00 GMT+0800 (中国标准时间)
 * Author = Shioho
 * FileBasename = aEventBase.ts
 * FileBasenameNoExtension = aEventBase
 * URL = db://assets/shioho/scripts/event/api/aEventBase.ts
 * ManualUrl = https://docs.cocos.com/creator/3.4/manual/zh/
 *
 */

import iEventManager from "./iEventManager";

export default abstract class aEventBase<TEvent> {

    private _eventMgr: iEventManager<TEvent>;

    protected abstract onInitEventMgr(): iEventManager<TEvent>;

    constructor() {
        this._eventMgr = this.onInitEventMgr();
    }

    protected addObserver(eventType: TEvent, func: Function) {
        this._eventMgr.addObserver(eventType, func);
    }

    protected removeObserver(eventType: TEvent, func: Function) {
        this._eventMgr.removeObserver(eventType, func);
    }

    protected dispatch(eventType: TEvent, ...args) {
        this._eventMgr.dispatch(eventType, args);
    }

    protected clear() {
        this._eventMgr.clear();
    }

}
